package com.centit.framework.ip.agentofd.controller;

import com.centit.framework.core.dao.CodeBook;
import com.centit.framework.ip.agentofd.po.OldNewfileinfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
 
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.centit.framework.ip.agentofd.service.OldNewfileinfoManager;
	

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSONArray; 
import com.centit.framework.common.JsonResultUtils;
import com.centit.framework.common.ResponseMapData;
import com.centit.framework.core.controller.BaseController;
import com.centit.support.database.utils.PageDesc;

/**
 * OldNewfileinfo  Controller.
 * create by scaffold 2018-07-30 
 * @author 脚手架，改成开发者的名字
 * 新旧文件转换映射信息表新旧文件转换映射信息表   
*/


@Controller
@RequestMapping("/agentofd/oldnewfileinfo")
public class OldNewfileinfoController  extends BaseController {
	private static final Log log = LogFactory.getLog(OldNewfileinfoController.class);
	
	@Resource
	private OldNewfileinfoManager oldNewfileinfoMag;	
    /**
     * 查询单个  新旧文件转换映射信息表 
	
	 * @param odlfileid  odlFileId
     *  
     * 
     * @param response    {@link HttpServletResponse}
     * @return {data:{}}
     */
    @RequestMapping(value = "/{odlfileid}", method = {RequestMethod.GET})
    public void getOldNewfileinfo(@PathVariable String odlfileid,HttpServletRequest request ,HttpServletResponse response) {
        Map<String, Object> searchColumn = convertSearchColumn(request);
        searchColumn.put("odlfileid",odlfileid);
        searchColumn.put(CodeBook.SELF_ORDER_BY," createtime desc ");
        List<OldNewfileinfo> infoLists= oldNewfileinfoMag.listObjects(searchColumn);
        OldNewfileinfo oldNewfileinfo= null;
        if(infoLists!=null&&infoLists.size()>0){
            oldNewfileinfo=infoLists.get(0);//默认获取最新的一条数据
        }
        JsonResultUtils.writeSingleDataJson(oldNewfileinfo, response);
    }
    
    /**
     * 新增 新旧文件转换映射信息表，业务只有新增的时候可用此方法，如有修改可用下面 新增或保存合并的方法
     *
     * @param oldNewfileinfo  {@link OldNewfileinfo}
     * @return
     */
    @RequestMapping(method = {RequestMethod.POST})
    public void createOldNewfileinfo(@Valid OldNewfileinfo oldNewfileinfo, HttpServletResponse response) {
    	 oldNewfileinfoMag.saveNewObject(oldNewfileinfo);
        JsonResultUtils.writeSingleDataJson("操作成功",response);
    }

    /**
     * 删除单个  新旧文件转换映射信息表 
	
	 * @param recid  recId
     */
    @RequestMapping(value = "/{recid}", method = {RequestMethod.DELETE})
    public void deleteOldNewfileinfo(@PathVariable String recid, HttpServletResponse response) {
    	
    	oldNewfileinfoMag.deleteObjectById( recid);
        
        JsonResultUtils.writeSingleDataJson("操作成功",response);
    } 
    
    /**
     * 新增或保存 新旧文件转换映射信息表 
    
	 * @param recid  recId
	 * @param oldNewfileinfo  {@link OldNewfileinfo}
     * @param response    {@link HttpServletResponse}
     */
    @RequestMapping(value = "/{recid}", method = {RequestMethod.PUT})
    public void updateOldNewfileinfo(@PathVariable String recid, 
    	@Valid OldNewfileinfo oldNewfileinfo, HttpServletResponse response) {
    	
    	
    	OldNewfileinfo dbOldNewfileinfo  =     			
    			oldNewfileinfoMag.getObjectById( recid);
        
        

        if (null != dbOldNewfileinfo) {//如果数据库数据存在，则是更新操作
        	dbOldNewfileinfo .copyNotNullProperty(oldNewfileinfo);//赋值页面不为空的值，小心页面空的字符串或者改写copyNotNullProperty方法，根据自己业务需要
        	oldNewfileinfoMag.mergeObject(dbOldNewfileinfo);
        } else {
             oldNewfileinfoMag.saveNewObject(oldNewfileinfo);//新增,注意主键赋值 UuidUtil.getTimeBasedUuid()，填写自己的业务时间，业务操作人等信息
        }

        JsonResultUtils.writeSingleDataJson("操作成功",response);
    }
}
